#include "dpLibrary\graphics.h"
#include "dpLibrary\dpWindows.h"
#include "AFObjectFactory.h"
#include "AFGraphics.h"


//loads wall objects from a file into a list
Sprite* loadWalls(int level)
{
  //sets up list for wall objects
  Sprite* dummy = CreateSprite(WHITE, 0, 0, 0, 0, 0, 0);
  Sprite* head = dummy;
  //wall params to be read in
  int color, locx, locy, width, height;
  FILE* infile;
  //string for the filename
  char filename[100];
  //get the right file of walls for each level
  switch (level)
  {
    case 1:
      GetCurrentDirectoryA(100, filename);
      strcat(filename, "\\level1walls.txt");
      break;
    case 2:
      GetCurrentDirectoryA(100, filename);
      strcat(filename, "\\level2walls.txt");
      break;
    default:
      break;
  }
  //open the file
  infile = fopen(filename,"r");
  if(infile)
  {
    while(!feof(infile))
    {
      //initialize and link the wall objects
      int read = fscanf(infile, "%x %i %i %i %i", &color, &locx, &locy, &width, &height);
      dummy->next = CreateSprite(color, 0, 0, locx, locy, width, height);
      dummy = dummy->next;
    }
    dummy->next = 0;
    return head;
  }
  return 0;
}

//frees the space allocated when the wall list was loaded
void unloadWalls(Sprite * walls)
{
  while(walls)
  {
    Sprite* temp = walls->next;
    free(walls);
    walls = temp;
  }
}